package com.bjxst;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class ObjectOutputStreamDemo {
    public static void main(String[] args) {
        ObjectOutputStream oos = null;
        try{
            //创建对象  ObjectOutputStream是处理流
            //处理流套一个缓冲流，再套一个字节流
            oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("d:nn1.txt")));
            oos.writeInt(10);
            oos.writeDouble(Math.random());
            oos.writeChar('a');
            oos.writeBoolean(true);
            oos.writeUTF("世界");
            //在文本中显示的是乱码，要用ObjectInputStream才能在程序中正常显示
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
                if(oos != null) oos.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
